<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch" label-width="68px">
      <el-form-item label="申请人" prop="shenqingrenTxt">
        <el-input
          v-model="queryParams.shenqingrenTxt"
          placeholder="请输入申请人"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="需求岗位" prop="xuqiugangwei">
        <el-input
          v-model="queryParams.xuqiugangwei"
          placeholder="请输入需求岗位"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="招聘日期">
        <el-date-picker
          v-model="daterangeZhaopinqishiriqi"
          style="width: 240px"
          value-format="yyyy-MM-dd"
          type="daterange"
          range-separator="-"
          start-placeholder="开始日期"
          end-placeholder="结束日期"
        ></el-date-picker>
      </el-form-item>
      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>

    <el-row :gutter="10" class="mb8">
      <el-col :span="1.5">
        <el-button
          type="primary"
          plain
          icon="el-icon-plus"
          size="mini"
          @click="handleAdd"
          v-hasPermi="['hrmanagement:ask:add']"
        >新增</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="success"
          plain
          icon="el-icon-edit"
          size="mini"
          :disabled="single"
          @click="handleUpdate"
          v-hasPermi="['hrmanagement:ask:edit']"
        >修改</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="danger"
          plain
          icon="el-icon-delete"
          size="mini"
          :disabled="multiple"
          @click="handleDelete"
          v-hasPermi="['hrmanagement:ask:remove']"
        >删除</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="warning"
          plain
          icon="el-icon-download"
          size="mini"
          @click="handleExport"
          v-hasPermi="['hrmanagement:ask:export']"
        >导出</el-button>
      </el-col>
      <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
    </el-row>

    <el-table v-loading="loading" :data="askList" @selection-change="handleSelectionChange">
      <el-table-column type="selection" width="55" align="center" />

      <el-table-column label="需求部门" align="center" prop="departName" />
      <el-table-column label="申请人" align="center" prop="shenqingrenTxt" />
      <el-table-column label="需求岗位" align="center" prop="xuqiugangwei" />
      <el-table-column label="招聘人数" align="center" prop="zhaopinrenshu" />
      <el-table-column label="招聘起始日期" align="center" prop="zhaopinqishiriqi" width="180">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.zhaopinqishiriqi, '{y}-{m}-{d}') }}</span>
        </template>
      </el-table-column>
      <el-table-column label="紧急程度" align="center" prop="jinjichengduTxt" >
       
        <template slot-scope="scope">
          <el-tag :type="scope.row.jinjichengduTxt==='一般'?'success':'danger'" >{{ scope.row.jinjichengduTxt }}</el-tag>
        </template>
      </el-table-column>
      <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
        <template slot-scope="scope">
          <el-button
            size="mini"
            type="text"
            icon="el-icon-edit"
            @click="handleUpdate(scope.row)"
            v-hasPermi="['hrmanagement:ask:edit']"
          >修改</el-button>
          <el-button
            size="mini"
            type="text"
            icon="el-icon-delete"
            @click="handleDelete(scope.row)"
            v-hasPermi="['hrmanagement:ask:remove']"
          >删除</el-button>
        </template>
      </el-table-column>
    </el-table>
    
    <pagination
      v-show="total>0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />

    <!-- 添加或修改招聘管理-招聘需求对话框 -->
    <el-dialog :title="title" :visible.sync="open" width="1000px" append-to-body>
      <el-form ref="form" :model="form" :rules="rules" label-width="80px">

<el-row >



  <el-col :span="12">
    <el-form-item label="申请人" prop="shenqingren"  onclick="open"  >


<UserSelect ref="userselect"    :open="userOpen" @cancel="userOpen=false"  @submit="submituser"></UserSelect>
<el-select v-model="form.shenqingren"  placeholder="请选择" @focus="useropen">
    <el-option
    placeholder="请选择用户"
      v-for="item in useroptions"
      :key="item.value"
      :label="item.label"
      :value="item.value">
    </el-option>
  </el-select>
          <!-- <el-input v-model="form.shenqingren" placeholder="请输入申请人"  @focus="useropen" /> -->
        </el-form-item>
</el-col>
<el-col :span="12">
              <el-form-item label="部门" label-width="80px" prop="departId">
                <treeselect
                  v-model="form.departId"
                  :options="deptOptions"
                  :show-count="true"
                  placeholder="请选择归属部门"
                />
              </el-form-item>
     

  </el-col>
<el-col :span="12">

    <el-col :span="12">
  <el-form-item label="需求岗位" prop="xuqiugangwei">
          <el-input v-model="form.xuqiugangwei" placeholder="请输入需求岗位" />
        </el-form-item>
</el-col>

<el-col :span="12">
  <el-form-item label="招聘人数" prop="zhaopinrenshu">
    <el-input
                type="number"
                oninput="value=value.replace(/^0|[^0-9]/g,'')"
                  v-model="form.zhaopinrenshu"
                  placeholder="请输入招聘人数"
                >
                <span slot="suffix">人</span>
              </el-input>
  
        </el-form-item>
</el-col> 
  
   
</el-col>

<el-col :span="12">
  <el-form-item label="初拟薪资" prop="chunixinzi">
    <el-input
                type="number"
                oninput="value=value.replace(/^0|[^0-9]/g,'')"
                  v-model="form.chunixinzi"
                  placeholder="请输入初拟薪资"
                >
                <span slot="suffix">元</span>
              </el-input>
          
        </el-form-item>
</el-col>

<el-col :span="12">
  <el-form-item label="年龄要求" prop="nianlingyaoqiu">
          <el-input v-model="form.nianlingyaoqiu" placeholder="请输入年龄要求" />
        </el-form-item>
</el-col>

<el-col :span="12">
  <el-form-item label="需求时间" prop="zhaopinqishiriqi">
          <el-date-picker clearable
            v-model="form.zhaopinqishiriqi"
            type="date"
            value-format="yyyy-MM-dd"
            placeholder="请选择需求时间">
          </el-date-picker>
        </el-form-item>
</el-col>


<el-col :span="24">
  <el-form-item label="学历要求" prop="xueliyaoqiuTxt">
          <el-input v-model="form.xueliyaoqiuTxt" placeholder="请输入学历要求"  />
        </el-form-item>
</el-col>

<el-col :span="24">
  <el-form-item label="其他要求" prop="qitayaoqiu">
          <el-input v-model="form.qitayaoqiu" placeholder="请输入其他要求"  type="textarea"/>
        </el-form-item>
</el-col>

<el-col :span="24">
  <el-form-item label="招聘原因" prop="zhaopinyuanyin">
          <el-input v-model="form.zhaopinyuanyin" type="textarea" placeholder="请输入内容" />
        </el-form-item>
</el-col>

<el-col :span="24">
  <el-form-item label="任职资格" prop="renzhizige">
          <el-input v-model="form.renzhizige" type="textarea" placeholder="请输入内容" />
        </el-form-item>
</el-col>

<el-col :span="24">

  <el-form-item label="工作职责" prop="zhuyaogongzuozhize">
          <el-input v-model="form.zhuyaogongzuozhize" type="textarea" placeholder="请输入内容" />
        </el-form-item>
</el-col>

<el-col :span="24">
  <el-form-item label="岗位要求" prop="gangweiyaoqiu">
          <el-input v-model="form.gangweiyaoqiu" type="textarea" placeholder="请输入内容" />
        </el-form-item>
</el-col>

<el-col :span="12">
  <el-form-item
                label="员工性质"
             
                prop="yuangongxingzhi"
              >
                <el-select
                  v-model="form.yuangongxingzhi"
                  placeholder="请选择员工性质"
                >
                  <el-option
                    v-for="dict in dict.type.sys_user_ygxz"
                    :key="dict.value"
                    :label="dict.label"
                    :value="dict.value"
                    placeholder="请选择员工性质"
                  ></el-option>
                </el-select>
              </el-form-item>


</el-col>

<el-col :span="12">
  <el-form-item label="紧急程度" prop="jinjichengduTxt">
    <el-radio-group v-model="form.jinjichengduTxt">
                  <el-radio label="一般">一般</el-radio>
                  <el-radio label="紧急">紧急</el-radio>
                </el-radio-group>
        </el-form-item>
        
</el-col>



</el-row>

       

  

</el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitForm">确 定</el-button>
        <el-button @click="cancel">取 消</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
import { listAsk, getAsk, delAsk, addAsk, updateAsk } from "@/api/hrmanagement/ask";
import { getUserSelect } from "@/api/system/user";

import { deptTreeSelect } from "@/api/system/user";

import UserSelect from "@/components/PeopleSelect/index";
import Treeselect from "@riophae/vue-treeselect";
import "@riophae/vue-treeselect/dist/vue-treeselect.css";
export default {
  dicts: [
   
    "sys_user_ygxz",
  
  ],
  name: "Ask",
  components: { Treeselect ,UserSelect},
  data() {
    return {
      useroptions:[],
      userOpen:false,
      deptOptions: [],

      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 招聘管理-招聘需求表格数据
      askList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 员工性质(显示名)时间范围
      daterangeZhaopinqishiriqi: [],
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        xuqiubumen: null,
        shenqingren: null,
        xuqiugangwei: null,
        zhaopinqishiriqi: null,
      },
      // 表单参数
      form: {},
      // 表单校验
      rules: {
       
        xuqiugangwei: [
            { required: true, message: '请选择需求岗位', trigger: 'blur' }
          ],
          chunixinzi: [
            { required: true, message: '请选择初拟薪资', trigger: 'blur' }
          ],
          nianlingyaoqiu: [
            { required: true, message: '请输入年龄要求', trigger: 'blur' }
          ],
          zhaopinqishiriqi: [
            { required: true, message: '请输入需求时间', trigger: 'blur' }
          ],
          yuangongxingzhi: [
            { required: true, message: '请选择员工性质', trigger: 'blur' }
          ],
      }
    };
  },
  created() {
    this.getList();
    deptTreeSelect().then((response) => {
        this.deptOptions = response.data;
      });
      getUserSelect().then(response => {
this.useroptions = response.data





      });
  },
  methods: {
    useropen(){
      console.log("打开选人组件");
        this.userOpen=true;
       },
      //选择人的确定按钮事件 submitPeople(nikeNamelist)方法传参一个默认接收用户昵称数组   submitPeople(peopleList,nikeNamelist)方法传参两个则是接收用户昵称数组和用户账号数组
        submituser(peopleList){
        this.form.shenqingren  = parseInt(peopleList.join(""))
        console.log(this.form.shenqingren);
        this.$forceUpdate()
          this.userOpen=false;
        },
    /** 查询招聘管理-招聘需求列表 */
    getList() {
      this.loading = true;
      this.queryParams.params = {};
      if (null != this.daterangeZhaopinqishiriqi && '' != this.daterangeZhaopinqishiriqi) {
        this.queryParams.params["beginZhaopinqishiriqi"] = this.daterangeZhaopinqishiriqi[0];
        this.queryParams.params["endZhaopinqishiriqi"] = this.daterangeZhaopinqishiriqi[1];
      }
      listAsk(this.queryParams).then(response => {
        this.askList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.form = {
        id: null,
        status: null,
        companyId: null,
        companyName: null,
        departId: null,
        departName: null,
        renzhizige: null,
        zhuyaogongzuozhize: null,
        xuqiubumen: null,
        xuqiubumenTxt: null,
        shenqingren: null,
        shenqingrenTxt: null,
        xuqiugangwei: null,
        zhaopinrenshu: null,
        chunixinzi: null,
        nianlingyaoqiu: null,
        zhaopinqishiriqi: null,
        xueliyaoqiu: null,
        xueliyaoqiuTxt: null,
        qitayaoqiu: null,
        zhaopinyuanyin: null,
        jinjichengdu: null,
        jinjichengduTxt: null,
        gangweiyaoqiu: null,
        yuangongxingzhi: null,
        yuangongxingzhiTxt: null,
        createBy: null,
        createTime: null,
        updateBy: null,
        updateTime: null
      };
      this.resetForm("form");
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.daterangeZhaopinqishiriqi = [];
      this.resetForm("queryForm");
      this.handleQuery();
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map(item => item.id)
      this.single = selection.length!==1
      this.multiple = !selection.length
    },
    /** 新增按钮操作 */
    handleAdd() {
      this.reset();
      this.open = true;
      this.title = "添加招聘需求";
    },
    /** 修改按钮操作 */
    handleUpdate(row) {
      this.reset();
      const id = row.id || this.ids
      getAsk(id).then(response => {
        this.form = response.data;
        this.open = true;
        this.title = "修改招聘需求";
      });
    },
    /** 提交按钮 */
    submitForm() {
      this.$refs["form"].validate(valid => {
        if (valid) {
          if (this.form.id != null) {
            updateAsk(this.form).then(response => {
              this.$modal.msgSuccess("修改成功");
              this.open = false;
              this.getList();
            });
          } else {
            addAsk(this.form).then(response => {
              this.$modal.msgSuccess("新增成功");
              this.open = false;
              this.getList();
            });
          }
        }
      });
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      const ids = row.id || this.ids;
      this.$modal.confirm('是否确认删除招聘管理-招聘需求编号为"' + ids + '"的数据项？').then(function() {
        return delAsk(ids);
      }).then(() => {
        this.getList();
        this.$modal.msgSuccess("删除成功");
      }).catch(() => {});
    },
    /** 导出按钮操作 */
    handleExport() {
      this.download('hrmanagement/ask/export', {
        ...this.queryParams
      }, `ask_${new Date().getTime()}.xlsx`)
    },
    

  }

};
</script>
